package coding.polymorphism;

//特征
class Characteristic {
    private String s;

    Characteristic(String s) {
        this.s = s;
        System.out.println("创建 Characteristic " + s);
    }

    protected void dispose() {
        System.out.println("销毁 Characteristic " + s);
    }
}

//描述
class Description {
    private String s;

    Description(String s) {
        this.s = s;
        System.out.println("创建 Description " + s);
    }

    protected void dispose() {
        System.out.println("销毁 Description " + s);
    }
}

//生物
class LivingCreature {
    private Characteristic p = new Characteristic("活的");
    private Description t = new Description("基本的生物");

    LivingCreature() {
        System.out.println("LivingCreature()");
    }

    protected void dispose() {
        System.out.println("LivingCreature dispose");
        t.dispose();
        p.dispose();
    }
}

//动物
class Animal extends LivingCreature {
    private Characteristic p = new Characteristic("has heart");
    private Description t = new Description("Animal not Vegetable");

    Animal() {
        System.out.println("Animal()");
    }

    @Override
    protected void dispose() {
        System.out.println("Animal dispose");
        t.dispose();
        p.dispose();
        super.dispose();
    }
}

//两栖动物
class Amphibian extends Animal {
    private Characteristic p = new Characteristic("可以在水中生活");
    private Description t = new Description("水和陆地");

    Amphibian() {
        System.out.println("Amphibian()");
    }

    @Override
    protected void dispose() {
        System.out.println("Amphibian dispose");
        t.dispose();
        p.dispose();
        super.dispose();
    }
}

//青蛙
public class Frog extends Amphibian {
    private Characteristic p = new Characteristic("Croaks");
    private Description t = new Description("Eats Bugs");

    public Frog() {
        System.out.println("Frog()");
    }

    @Override
    protected void dispose() {
        System.out.println("Frog dispose");
        t.dispose();
        p.dispose();
        super.dispose();
    }

    public static void main(String[] args) {
        Frog frog = new Frog();
        System.out.println("Bye!");
        frog.dispose();
    }
}
